<?php
	function doclick($id){
		global $prefix;
		
		$sql="update ".$prefix."article set click=click+1 where id=".$id;
		if(!mysql_query($sql)){
			die("错误的参数ID");
		}
	}

	function doquery($id){
		global $prefix;
		
		$sql="select pid,folder,name from ".$prefix."column where id=".$id;
		$result=mysql_query($sql);
		if($row=mysql_fetch_array($result)){
			return $row;
		}
	}
	//取得$id所对应的栏目的路径
	function get_catalog_path($id){
		global $website;
		
		$arr=doquery($id);
		$name=$arr['name'];
		//$str=$arr['folder'];
		$str='';
		while($arr['pid']!=0){
			$arr=doquery($arr['pid']);
			if($arr['folder']){
				$str=$arr['folder']."/".$str;
			}
		}
		return $str;
	}
	//取得$id所对应的栏目的完整路径
	function get_catalog_path_all($id){
		global $website;
		
		$arr=doquery($id);
		$name=$arr['name'];
		$str=$arr['folder'];
		while($arr['pid']!=0){
			$arr=doquery($arr['pid']);
			if($arr['folder']){
				$str=$arr['folder']."/".$str;
			}
		}
		return $str;
	}
	//取得栏目ID为$id的栏目的所有子栏目，并用逗号分隔开
	function get_all_sub_catalog($id){
		global $prefix;
		$str=$id;
		
		$sql="select id from ".$prefix."column where pid=".$id;
		$result=mysql_query($sql);
		while($row=mysql_fetch_array($result)){
			$str.=",".get_all_sub_catalog($row['id']);
		}
		return $str;
	}
	//取得$id所对应的栏目的链接
	function get_catalog_link($id){
		global $website;
		
		$arr=doquery($id);
		$name=$arr['name'];
		$str=$arr['folder'];
		while($arr['pid']!=0){
			$arr=doquery($arr['pid']);
			if($arr['folder']){
				$str=$arr['folder']."/".$str;
			}
		}
		return "<a href='".$website."/".$str."/' title='".$name."'>".$name."</a>";
	}
	//取得当前位置字符串
	function get_position_str($id){
		$str=get_catalog_link($id);
		$arr=doquery($id);
		while($arr['pid']!=0){
			$str=get_catalog_link($arr['pid'])." > ".$str;
			$arr=doquery($arr['pid']);
		}
		return $str;
	}
	//取得当前栏目的上级目录中第一个类型为 栏目组 的栏目资料
	function get_group_catalog($id){
		global $prefix;
		
		$sql="select * from ".$prefix."column where id=".$id;
		$result=mysql_query($sql);
		if($row=mysql_fetch_array($result)){
			$arr=$row;
		}
		if($arr['type']!='group' && $arr['id']!=0){
			return get_group_catalog($arr['pid']);
		}else{
			return $arr;
		}
	}
?>
